package Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MaxConcApptDB
{
	public static void update(String newValue)
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		String select = "UPDATE maxconcappt SET number = ? WHERE number > 0";
		
		try
		{
			stmt = con.prepareStatement(select);
			stmt.setString(1, newValue);
			
			stmt.executeUpdate();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}
	}
	
	public static int select()
	{
		Connection con = DBConnection.connect(true);
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM maxconcappt LIMIT 1";

		int maxNo = 0;
		
		try
		{
			stmt = con.prepareStatement(select);
			// stmt.setString(1, credID);
			rs = stmt.executeQuery();
			while (rs.next())
			{
				maxNo = rs.getInt("Number");
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				if (con != null)
					con.close();
			}
			catch (SQLException e)
			{
			}
		}

		return maxNo;
	}
}
